package com.tenglong.teacher.ui.setting.setting;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.cuotibao.zhuoxiao.basics.GlobalConstant;
import com.tenglong.teacher.R;
import com.tenglong.teacher.ui.common.activity.BaseActivity;

public class MessageActivity extends BaseActivity {

    public static final String KEY_MESSAGE_DIRECTION = "key_message_direction";
    public static final int VERIFY_MESSAGE_DIRECTION = 1;
    public static final int INFORM_MESSAGE_DIRECTION = 2;
    public static final String KEY_MESSAGE_NUMBER = "key_message_number";
    private View verifyPoint;
    private int informMessageNum;
    private int messageDirection = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message);
        initData();
        initView();
        setListeners();
        if (messageDirection == VERIFY_MESSAGE_DIRECTION) {
            onClick(findViewById(R.id.message));
        } else if (messageDirection == INFORM_MESSAGE_DIRECTION) {
            onClick(findViewById(R.id.inform));
        }
    }

    private void initData() {
        messageDirection = getIntent().getIntExtra(KEY_MESSAGE_DIRECTION, 0);
        informMessageNum = getIntent().getIntExtra(KEY_MESSAGE_NUMBER, 0);
    }

    private void initView() {
        setTitle("消息");
        verifyPoint = findViewById(R.id.verifyPoint);
        verifyPoint.setVisibility(informMessageNum == 0 ? View.GONE : View.VISIBLE);
    }

    private void setListeners() {
        findViewById(R.id.inform).setOnClickListener(this);
        findViewById(R.id.message).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.inform:
                startActivity(new Intent(this, InformActivity.class));
                break;
            case R.id.message:
                startActivityForResult(new Intent(this, VerifyMessageActivity.class), GlobalConstant.REQUEST_CODE_VERIFY_MESSAGE_ACTIVITY);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
                case GlobalConstant.REQUEST_CODE_VERIFY_MESSAGE_ACTIVITY:
                    if (data != null) {
                        informMessageNum = data.getIntExtra(VerifyMessageActivity.KEY_VERIFY_MESSAGE_NUMBER, 0);
                        setResult(Activity.RESULT_OK, data);
                    }
                    verifyPoint.setVisibility(informMessageNum == 0 ? View.GONE : View.VISIBLE);
                    break;
            }
        }
    }
}
